package com.pshare.artemis.order.service;

import java.util.Date;
import java.util.List;

import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.pshare.artemis.order.bean.Order;
import com.pshare.artemis.order.enums.OverdueState;
import com.pshare.artemis.order.mapper.OrderMapper;
import com.pshare.artemis.parkingdevice.bean.Gateway;
import com.pshare.artemis.parkingdevice.bean.ParkingDevice;
import com.pshare.artemis.parkingdevice.enums.UpDownState;
import com.pshare.framework.mapper.BaseMapper;
import com.pshare.framework.service.BaseService;
import com.pshare.util.DateUtils;
import com.pshare.util.HttpUtils;
import com.pshare.util.SysPropertyUtils;

@Service
public class OrderService extends BaseService<Long,Order>{

	@Autowired
	private OrderMapper orderMapper;
	
	@Override
	protected BaseMapper<Long, Order> getBaseMapper() {
		return orderMapper;
	}
	
	public List<Order> getByMac(String mac){
		return orderMapper.getByMac(mac);
	}
	
	public List<Order> getByOpenId(String openId){
		return orderMapper.getByOpenId(openId);
	}
	//是否有未过期订单
	public Boolean hasNoOverDue(String openId){
		boolean t=false;
		List<Order> list=this.getByOpenId(openId);
		for(int i=0;i<list.size();i++){
			int cdate=DateUtils.minutesBetween(list.get(i).getStartTime(), new Date());
			if(cdate<=30){
				t=true;
			}
		}
		return t;
	}
	
	public List<Order> getAll(){
		return orderMapper.getAll();
	}
	
	public void saveOrUpdate(Order bean){
		List<Order> orders=this.getByMac(bean.getLockMac());
		
		if(orders.size()>0){
			this.update(bean);
		}else{
			this.add(bean);
		}
	}
	
}
